#pragma once

namespace TestFramework
{
    template <class T>
    class TestAutoPtr
    {
    public:
        typedef T ValueType;

        TestAutoPtr()
            : Ptr(0)
        {
        }

        explicit TestAutoPtr(ValueType* ptr)
            : Ptr(ptr)
        {
        }

        TestAutoPtr(TestAutoPtr& autoPtr)
        {
            Ptr = autoPtr.Release();
        }

        void Reset(ValueType* ptr = 0)
        {
            if (Ptr != ptr)
            {
                delete Ptr;
                Ptr = ptr;
            }
        }

        ValueType* Release()
        {
            ValueType* tmp = Ptr;
            Ptr = 0;
            return tmp;
        }

        ~TestAutoPtr()
        {
            delete Ptr;
        }

        T* Get() const
        {
            return Ptr;
        }

        TestAutoPtr& operator=(TestAutoPtr& ptr)
        {
            Ptr = ptr.Release();
            return *this;
        }

        ValueType* operator->()
        {
            return Ptr;
        }

        ValueType& operator*()
        {
            return *Ptr;
        }

    private:
        ValueType* Ptr;
    };
}
